// import Vue from 'vue'
export default {
    install(Vue) {
        const feedBackMusic = {
            touch: "touch",
            click: "角色",
            collect: "收集",
            explain: "详情",
            univer: "万能",
            level: "升级",
            press: "激活",
            put: "放入",
            plo: "保存",
            suc: "任务成功",
            los: "任务失败",
            good: "good",
            book: "book",
            perfect: "perfect",
            retry: "retry"
        }
        for (const index in feedBackMusic) {
            const Audiofunction = index + "Music"
            Vue.prototype[Audiofunction] = () => {
                const audio = document.getElementById("feedBackMusic")
                audio.src = "https://hz-huibenxia.oss-cn-shenzhen.aliyuncs.com/Static-library/music/" + feedBackMusic[index] + ".mp3"
                const playPromise = audio.play()
                if (playPromise) {
                    playPromise.then(() => {

                    }).catch(() => {

                    })
                }
            }
        }
        Vue.prototype.diologMusic = (option) => {
            return new Promise(resolve => {
                const diologMusic = document.getElementById("diologMusic")
                const resultOption = $.extend({
                    src: diologMusic.src,
                    play: true,
                    volume: 1
                }, option)
                if (resultOption.play) {
                    diologMusic.src = resultOption.src
                    diologMusic.volume = resultOption.volume
                    diologMusic.play()
                    diologMusic.onended = () => {
                        resolve()
                    }
                }
                else {
                    diologMusic.pause()
                }
            })
        }
        Vue.prototype.questionMusic = (param) => {
            const questionMusic = document.getElementById("questionMusic");
            param ? questionMusic.play() : questionMusic.pause()
        }
        Vue.prototype.answerMusic = (param) => {
            const answerMusic = document.getElementById("answerMusic");
            param ? answerMusic.play() : answerMusic.pause()
        }
        Vue.prototype.picbookAudioMusic = (option) => {
            return new Promise(resolve => {
                const picbookAudioMusic = document.getElementById("picbookAudioMusic")
                const resultOption = $.extend({
                    src: "",
                    volume: null,
                    play: true
                }, option)
                if (resultOption.volume) {
                    picbookAudioMusic.volume = resultOption.volume
                    return
                }
                if (resultOption.play) {
                    picbookAudioMusic.src = resultOption.src
                    picbookAudioMusic.play()
                    picbookAudioMusic.onended = () => {
                        resolve()
                    }
                }
                else {
                    picbookAudioMusic.pause()
                }
            })
        }
        Vue.prototype.parseTextMusic = (option) => {
            const resultOption = $.extend({
                src: "",
                play: true,
                start: null,
                end: null
            }, option)
            if (resultOption.play) {
                const parseTextAudio = document.getElementById("parseTextAudio")
                parseTextAudio.src = resultOption.src
                parseTextAudio.play()
                if (resultOption.start) {
                    let isStart = false
                    parseTextAudio.onplay = () => {
                        if (!isStart) resultOption.start()
                        isStart = true
                    }
                }
                if (resultOption.end) {
                    let isEnd = false
                    parseTextAudio.onended = () => {
                        if (!isEnd) resultOption.end()
                        isEnd = true
                    }
                }
            } else {
                const parseTextAudio = document.getElementById("parseTextAudio")
                parseTextAudio.pause()
            }
        }
    }
}
